package cn.tedu.cgb2110boot02.request;
/**实验请求转发*/
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/testa")
public class ServletA extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("ServletA的doGet方法被执行...");
        //请求转发:  实现 访问 A 时 , A 背后调用 B 的效果
        //参数是 目标资源的访问规则,目标资源必须是在同一个项目里
        //特点: 地址栏不变 + 同一个request对象
        request.setAttribute("name","jack");//放在转发之前，要不然不会执行
        request.getRequestDispatcher("/testb").forward(request,response);
    }
}
